﻿using System.Text;

// 此处扩展的是netcore自身的方法，所以使用系统命名空间
namespace Microsoft.AspNetCore.Http
{
    /// <summary>
    /// HttpRequest自定义扩展
    /// </summary>
    public static class HttpRequestExtensions
    {
        #region 获取当前请求页面的url
        /// <summary>
        /// 获取当前请求页面的url
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetRequestUrl(this HttpRequest request)
        {
            return $"{request.PathBase}{request.Path}{request.QueryString}";

        }

        /// <summary>
        /// 获取当前请求页面的url
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetAbsoluteUri(this HttpRequest request)
        {
            return new StringBuilder()
                .Append(request.Scheme)
                .Append("://")
                .Append(request.Host)
                .Append(request.PathBase)
                .Append(request.Path)
                .Append(request.QueryString)
                .ToString();
        }
        #endregion
    }
}
